From 2cab7c0f91a8cea5d978ca2934aa9d7e478edd07 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Tue, 30 May 2017 13:19:49 +0200 Subject: [PATCH] Process content headers when metadata is empty The new width/height override means that files without any metadata can get content headers. Bug: T150741 Change-Id: I92199a4aa9e0408572ebf7d8e4c04cd0196f0d0a --- includes/filerepo/file/File.php | 12 +++++++----- includes/filerepo/file/LocalFile.php | 4 ++++ includes/media/DjVu.php | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 0ad05274cf..53211febab 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -2165,13 +2165,15 @@ abstract class File implements IDBAccessObject { if ( $handler ) { $metadata = $this->getMetadata(); - if ( $metadata ) { - if ( is_string( $metadata ) ) { - $metadata = MediaWiki\quietCall( 'unserialize', $metadata ); - } + if ( is_string( $metadata ) ) { + $metadata = MediaWiki\quietCall( 'unserialize', $metadata ); + } - return $handler->getContentHeaders( $metadata, $this->getWidth(), $this->getHeight() ); + if ( !is_array( $metadata ) ) { + $metadata = []; } + + return $handler->getContentHeaders( $metadata, $this->getWidth(), $this->getHeight() ); } return []; diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 8514cc8d29..a90156fad1 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1202,6 +1202,10 @@ class LocalFile extends File { if ( $handler ) { $metadata = MediaWiki\quietCall( 'unserialize', $props['metadata'] ); + if ( !is_array( $metadata ) ) { + $metadata = []; + } + $options['headers'] = $handler->getContentHeaders( $metadata, $props['width'], $props['height'] ); diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php index dcd276c6ed..f260850acc 100644 --- a/includes/media/DjVu.php +++ b/includes/media/DjVu.php @@ -471,7 +471,7 @@ class DjVuHandler extends ImageHandler { * @since 1.30 */ public function getContentHeaders( $metadata, $fallbackWidth = null, $fallbackHeight = null ) { - if ( !is_array( $metadata ) || !isset( $metadata['xml'] ) ) { + if ( !isset( $metadata['xml'] ) ) { return []; } -- 2.20.1